// pages/history/index.js
const App = getApp()
let { windowWidth } = wx.getWindowInfo();
const dayjs = require('dayjs');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        chartWidth: windowWidth + 'px',
        chartHeight: (windowWidth * 9 / 16) + 'px',
        chartHeight2: (windowWidth * 9 / 16 * 3) + 'px',
        month: '',
        minDate:dayjs('2024-01-20').valueOf(),
        maxDate:dayjs().valueOf(),
        monthtext: '',
        List: [],
        showDialog2: false,
        showpopup: false,
        checked: false,
        option: {},
        optionLagu: {},
        optionTeam: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // this.onInstance()
        // const currentDate = new Date();
        // const year = currentDate.getFullYear(); // 获取当前年份

        // let month = currentDate.getMonth() + 1; // 获取当前月份，注意要加1
        // if (month < 10) {
        //     month = '0' + month; // 在月份小于10时前面添加0
        // }
        this.setData({ monthtext:dayjs().subtract(18,'hour').format("YYYY-MM-DD") }, () => {
            this.getlist()
        });

    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    async onPullDownRefresh() {
        await this.getlist()
        wx.stopPullDownRefresh()
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        //   return {
        //     title: '当期竞彩测算',
        //     path: promotioncode ? `/pages/index/index?promotioncode=${promotioncode}` : `/pages/index/index`,
        //     imageUrl: '../../images/logo_share.jpg'
        // }
    },
    async onChange() {
        this.setData({ checked: !this.data.checked }, () => {
            this.getlist()
        })
    },
    async openCalendar() {
        this.setData({ showpopup: !this.data.showpopup })
    },
    async onInput(event) {
      console.log(event)
        const currentDate = new Date(event.detail);
        const year = currentDate.getFullYear(); // 获取当前年份
        let month = currentDate.getMonth() + 1; // 获取当前月份，注意要加1
        if (month < 10) {
            month = '0' + month; // 在月份小于10时前面添加0
        }
        this.setData({
            // month: event.detail,
            monthtext: dayjs(event.detail).format('YYYY-MM-DD'),
            showpopup: false
        }, () => {
            this.getlist()
        });
    },
    async getlist() {
        App.showLoading();
        let {
            monthtext
        } = this.data;
        try {
            let {
                data
            } = await App.$http("/football/firstlists", {
                monthtext,
            }, 'GET');
            this.setData({
                List: data,
                showDialog: false,
                loading: false
            });
            wx.hideLoading();
        } catch (error) {
            this.setData({
                showDialog2: true,
                tipsText: error,
            });
            wx.hideLoading();
        }
    }
})